
/* 
 * File:   ResourceManager.h
 * Author: RedEyedKiller
 *
 * Created on 22 Ιούνιος 2011, 1:39 πμ
 */

#ifndef RESOURCEMANAGER_H
#define	RESOURCEMANAGER_H

#include "ResourcePool.h"
#include "Singleton.h"

/**
 * A singleton class that handles all resources.
 * Each different resource type has its own pool.
 * For each of this pool a GetResource(const char* rname) method should be created.
 */
class ResourceManager
{
    SingletonClass(ResourceManager)
public:
    virtual ~ResourceManager();

    /**
     * Initializes all pools. Sets up default path etc.
     */
    void InitializePools();

    /// a pair of geting image resource.
    Resource<sdl::Image>* GetImage(const char* name);
    Resource<sdl::Image>* GetImage(const char* path, const char* name);

    /// a pair of geting image resource.
    Resource<gl::Texture>* GetTexture(const char* name);
    Resource<gl::Texture>* GetTexture(const char* path, const char* name);

    /// a pair of geting Sound resource.
    Resource<al::Sound>* GetSound(const char* name);
    Resource<al::Sound>* GetSound(const char* path, const char* name);

    /// a pair of geting font resource.
    Resource<sdl::Font>* GetFont(const char* name, int size);
    Resource<sdl::Font>* GetFont(const char* path, const char* name, int size);


    /**
     * Garbage collects all unused resources.
     * @param killEmAll if true important resources will be collected as well if they have no references.
     */

    void GarbageCollect(bool killEmAll = false);

private:

    /**
     * A pool to hold sdl::Images
     */
    ResourcePool<sdl::Image> imagePool;

    /**
     * A pool to hold sdl::Font
     */
    ResourcePool<sdl::Font> fontPool;

    /** 
     * A pool to hold gl::Textures
     */
    ResourcePool<gl::Texture> texturePool;

    /**
     * A pool to hold Sounds
     * Because of the nature of sounds all sounds created are set to important.
     */
    ResourcePool<al::Sound> soundPool;
};

#endif	/* RESOURCEMANAGER_H */

